<template>
    <view class="login">
        <view class="title">
            <view>
                <span>Welcome to the system!</span>
            </view>
            <view>
                <span>欢迎登录私人新闻查阅系统</span>
            </view>
        </view>
        <view class="form">
            <input class="uni-input" v-model="username" type="text" placeholder="请输入账号" />
            <input class="uni-input" v-model="password" password type="text" placeholder="请输入密码" />
        </view>
        <view class="btn">
            <button @tap="login" >立即登录</button>
            <view class="tip" >
                <text type="primary" @click="addnew">没有账号，请先注册</text>
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                username: "",
                password: ""
            }
        },
        methods: {
            login() {
                uniCloud.callFunction({
                    name: "Login-hotel",
                    data: {
                        username: this.username,
                        password: this.password
                    },
                    success: (res) => {
                        console.log(res);
                        if (res.result.code == 200) {
                            uni.showToast({
                                title: "登录成功"
                            })
                            setTimeout(() => {
                                wx.switchTab({
                                    url: "/pages/index/index"
                                })
                                //把用户名存储到本地存储中
                                uni.setStorageSync("name", res.result.user.name)
                            }, 2000)
    
                        } else {
                           7
                            uni.showToast({
                                title: res.result.msg,
                                icon: "none"
    
                            })
                        }
                    }
                })
            },
            addnew() {
                uni.navigateTo({
                    url: "/pages/Enrool-hotel/Enrool-hotel"
                })
            },
        }
    }
</script>
<style lang="scss">
    .login {
        padding: 100rpx 40rpx;
        background: url("../../static/login.png");
        background-size: 100% 100%;
        height: 100vh;

        .title {
            font-weight: bolder;
            font-size: 40rpx;
            text-align: center;
        }

        .form {
            margin-top: 100rpx;

            input {
                border-bottom: 1px solid #d6d6d6;
                margin-bottom: 40rpx;
            }
        }

        .btn {
            margin-top: 100rpx;

            button {
                background-color: #11d77e;
                color: white;
            }

            .tip {
                text-align: right;
                color: gray;
                margin-top: 20rpx;

            }
        }
    }
</style>
